using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDRARCHIV
    {
        public DataRow Convert2DRARCHIV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDRARCHIV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DARMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DARLFDNR"] = " ".PadRight(0 ); 
         dwReturn["DARARCHIV"] = " ".PadRight(8 ); 
         dwReturn["DARORDNER"] = " ".PadRight(8 ); 
         dwReturn["DARDOKUMENT"] = " ".PadRight(8 ); 
         dwReturn["DARKURZBEZ"] = " ".PadRight(10 ); 
         dwReturn["DARBEZ"] = " ".PadRight(50 ); 
         dwReturn["DARDATUM"] = " ".PadRight(0 ); 
         dwReturn["DARZEIT"] = " ".PadRight(0 ); 
         dwReturn["DARBENID"] = " ".PadRight(8 ); 
         dwReturn["DARAUFTNR"] = " ".PadRight(4 ); 
         dwReturn["DARART"] = " ".PadRight(1 ); 
         dwReturn["DARFILE"] = " ".PadRight(56 ); 
         dwReturn["DARLIST"] = " ".PadRight(8 ); 
         dwReturn["DARABZKZ"] = " ".PadRight(1 ); 
         dwReturn["DARABZDAT"] = " ".PadRight(0 ); 
         dwReturn["DARABZBENID"] = " ".PadRight(8 ); 
         dwReturn["DARMEDIUM"] = " ".PadRight(40 ); 
         dwReturn["DARLOEKZ"] = " ".PadRight(1 ); 
         dwReturn["DARLOEDAT"] = " ".PadRight(0 ); 
         dwReturn["DARLOEBENID"] = " ".PadRight(8 ); 
         dwReturn["DARFILLER"] = " ".PadRight(55 ); 
         dwReturn["DARNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["DARNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["DARAENDAT"] = " ".PadRight(0 ); 
         dwReturn["DARAENBEN"] = " ".PadRight(8 ); 
         dwReturn["DARAENDZL"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDRARCHIV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDRARCHIV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDRARCHIV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDRARCHIV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDRARCHIV(dwLocal, ITXDBVERSION);
            }
            UpdateDRARCHIV(dwLocal);
        }
        public void InsertDRARCHIV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DRARCHIV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDRARCHIV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DRARCHIV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DRARCHIV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DRARCHIV";
            Return = Result;
            return Return;
        }
        public void DeleteDRARCHIV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DRARCHIV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDRARCHIV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DRARCHIV SET "
                    +"DARMANDANT= :DARMANDANT,"
                    +"DARLFDNR= :DARLFDNR,"
                    +"DARARCHIV= :DARARCHIV,"
                    +"DARORDNER= :DARORDNER,"
                    +"DARDOKUMENT= :DARDOKUMENT,"
                    +"DARKURZBEZ= :DARKURZBEZ,"
                    +"DARBEZ= :DARBEZ,"
                    +"DARDATUM= :DARDATUM,"
                    +"DARZEIT= :DARZEIT,"
                    +"DARBENID= :DARBENID,"
                    +"DARAUFTNR= :DARAUFTNR,"
                    +"DARART= :DARART,"
                    +"DARFILE= :DARFILE,"
                    +"DARLIST= :DARLIST,"
                    +"DARABZKZ= :DARABZKZ,"
                    +"DARABZDAT= :DARABZDAT,"
                    +"DARABZBENID= :DARABZBENID,"
                    +"DARMEDIUM= :DARMEDIUM,"
                    +"DARLOEKZ= :DARLOEKZ,"
                    +"DARLOEDAT= :DARLOEDAT,"
                    +"DARLOEBENID= :DARLOEBENID,"
                    +"DARFILLER= :DARFILLER,"
                    +"DARNEUDAT= :DARNEUDAT,"
                    +"DARNEUBEN= :DARNEUBEN,"
                    +"DARAENDAT= :DARAENDAT,"
                    +"DARAENBEN= :DARAENBEN,"
                    +"DARAENDZL= :DARAENDZL,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DARMANDANT", OracleType.NVarChar).Value = dwData["DARMANDANT"].ToString(); 
          or1.Parameters.Add("DARLFDNR", OracleType.NVarChar).Value = dwData["DARLFDNR"].ToString(); 
          or1.Parameters.Add("DARARCHIV", OracleType.NVarChar).Value = dwData["DARARCHIV"].ToString(); 
          or1.Parameters.Add("DARORDNER", OracleType.NVarChar).Value = dwData["DARORDNER"].ToString(); 
          or1.Parameters.Add("DARDOKUMENT", OracleType.NVarChar).Value = dwData["DARDOKUMENT"].ToString(); 
          or1.Parameters.Add("DARKURZBEZ", OracleType.NVarChar).Value = dwData["DARKURZBEZ"].ToString(); 
          or1.Parameters.Add("DARBEZ", OracleType.NVarChar).Value = dwData["DARBEZ"].ToString(); 
          or1.Parameters.Add("DARDATUM", OracleType.NVarChar).Value = dwData["DARDATUM"].ToString(); 
          or1.Parameters.Add("DARZEIT", OracleType.NVarChar).Value = dwData["DARZEIT"].ToString(); 
          or1.Parameters.Add("DARBENID", OracleType.NVarChar).Value = dwData["DARBENID"].ToString(); 
          or1.Parameters.Add("DARAUFTNR", OracleType.NVarChar).Value = dwData["DARAUFTNR"].ToString(); 
          or1.Parameters.Add("DARART", OracleType.NVarChar).Value = dwData["DARART"].ToString(); 
          or1.Parameters.Add("DARFILE", OracleType.NVarChar).Value = dwData["DARFILE"].ToString(); 
          or1.Parameters.Add("DARLIST", OracleType.NVarChar).Value = dwData["DARLIST"].ToString(); 
          or1.Parameters.Add("DARABZKZ", OracleType.NVarChar).Value = dwData["DARABZKZ"].ToString(); 
          or1.Parameters.Add("DARABZDAT", OracleType.NVarChar).Value = dwData["DARABZDAT"].ToString(); 
          or1.Parameters.Add("DARABZBENID", OracleType.NVarChar).Value = dwData["DARABZBENID"].ToString(); 
          or1.Parameters.Add("DARMEDIUM", OracleType.NVarChar).Value = dwData["DARMEDIUM"].ToString(); 
          or1.Parameters.Add("DARLOEKZ", OracleType.NVarChar).Value = dwData["DARLOEKZ"].ToString(); 
          or1.Parameters.Add("DARLOEDAT", OracleType.NVarChar).Value = dwData["DARLOEDAT"].ToString(); 
          or1.Parameters.Add("DARLOEBENID", OracleType.NVarChar).Value = dwData["DARLOEBENID"].ToString(); 
          or1.Parameters.Add("DARFILLER", OracleType.NVarChar).Value = dwData["DARFILLER"].ToString(); 
          or1.Parameters.Add("DARNEUDAT", OracleType.NVarChar).Value = dwData["DARNEUDAT"].ToString(); 
          or1.Parameters.Add("DARNEUBEN", OracleType.NVarChar).Value = dwData["DARNEUBEN"].ToString(); 
          or1.Parameters.Add("DARAENDAT", OracleType.NVarChar).Value = dwData["DARAENDAT"].ToString(); 
          or1.Parameters.Add("DARAENBEN", OracleType.NVarChar).Value = dwData["DARAENBEN"].ToString(); 
          or1.Parameters.Add("DARAENDZL", OracleType.NVarChar).Value = dwData["DARAENDZL"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
